package design.chain;

/**
 * @author yuqi<307530884@qq.com> <2017/3/22>
 * @version 1.0
 * @since 1.0
 */
public class FilterImpl implements Filter {

    private int filterCode;

    private String filterName;

    public FilterImpl(int filterCode, String filterName) {
        this.filterCode = filterCode;
        this.filterName = filterName;
    }

    @Override
    public Response doFilter(Request request, FilterChain filterChain) {

        System.out.println(filterName + " 开始处理请求");

        if(RequestUtils.belong(request, filterCode)){
            System.out.println(filterName + " 可以处理这个请求");
            return ResponseUtils.successResponse(filterName);
        }

        System.out.println(filterName + " 不能处理这个请求");

        Response response = filterChain.doFilter(request);

        System.out.println(filterName + " 返回处理结果：" + response);

        return response;
    }
}
